package ex05.pyrmont.valves;

import org.apache.catalina.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class HttpMethodLoggerValve implements Valve, Contained {

    protected Container container;

    @Override
    public String getInfo() {
        return this.getClass().getName();
    }

    @Override
    public void invoke(Request request, Response response, ValveContext context) throws IOException, ServletException {

        context.invokeNext(request, response);

        HttpServletRequest httpRequest = (HttpServletRequest)request;

        System.out.println("------------" + this.getInfo() + "----------------");
        System.out.println(httpRequest.getMethod() + " " + httpRequest.getRequestURI() + " " + httpRequest.getProtocol());
        System.out.println("------------" + this.getInfo() + "----------------");


    }

    @Override
    public Container getContainer() {
        return this.container;
    }

    @Override
    public void setContainer(Container container) {
        this.container = container;
    }
}
